
package models.spider.sink;

import models.spider.ISpider;
import models.spider.request.Request;
import play.Logger;

/**
 * 
 * @author laurent@opprecht.info
 */
public class Log extends SinkBase {

    public static final int INFO_LEVEL    = 0;
    public static final int WARNING_LEVEL = 10;
    public static final int DEBUG_LEVEL   = 20;
    public static final int ERROR_LEVEL   = 30;
    public static final Log INFO          = new Log(INFO_LEVEL);
    public static final Log WARNING       = new Log(WARNING_LEVEL);
    public static final Log DEBUG         = new Log(DEBUG_LEVEL);
    public static final Log ERROR         = new Log(ERROR_LEVEL);
    protected int           level         = 0;

    public Log(final int level) {
        this.level = level;
    }

    public Log() {
        this(Log.INFO_LEVEL);
    }

    @Override
    public void sink(final Request object, final ISpider spider) {
        String message = object.toString();        
        switch (level) {
        case Log.INFO_LEVEL:
            Logger.info(message);
            break;
        case Log.WARNING_LEVEL:
            Logger.warn(message);
            break;
        case Log.DEBUG_LEVEL:
            Logger.debug(message);
            break;
        case Log.ERROR_LEVEL:
            Logger.error(message);
            break;
        default:
            Logger.info(message);
            break;
        }
    }
}
